package com.example.demo.mapper;

import com.example.demo.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper {
    @Select("SELECT * FROM user WHERE id = #{id}")
    User getById(Long id);

    @Select("SELECT * FROM user")
    List<User> getAll();
    // 检查用户名是否存在
    @Select("SELECT COUNT(*) FROM user WHERE username = #{username}")
    int countByUsername(String username);
    //添加用户
    @Insert("INSERT INTO user(username, password, time) VALUES(#{username}, #{password},  NOW())")
    boolean insert(User user);



}
